package com.hwatsang.service.impl;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.hwatsang.dao.ProductDao;
import com.hwatsang.model.Product;
import com.hwatsang.service.ProductService;

public class ProductServiceImpl implements ProductService {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ProductServiceImpl.class);
	
	@Autowired
	private ProductDao productDao;
	
	@Override
	public String createProduct(Product product) {
		
		LOGGER.info("Saving product with name {}.", product.getName());
		
		product.setGmtCreate(new Date());		
		return productDao.createProduct(product);
	}
	
	@Override
	public boolean updateProductImgPath(String productId, String path) {
		
		LOGGER.info("Updating product {}'s picture path to {}.", productId, path);
		
		Product product = productDao.getProductById(productId);
		product.setPicturePath(path);
		return productDao.updateProduct(product);
	}

	@Override
	public boolean updateProduct(Product product) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public List<Product> getAllPublishedProducts() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Product> getAllProducts(int startPage, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

}
